local zhaolei = fk.CreateSkill {
  name = "3s__zhaolei",
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["3s__zhaolei"] = "照垒",
  [":3s__zhaolei"] = "每局限两次，你能视为使用【酒】，且额外触发另一项效果；你每局游戏至多使用三张【杀】且无次数限制，上述中的一项使用到上限后，你翻面，重置另一项，然后你于此牌结算后视为使用【火攻】。",
  ["#3s__zhaolei-analeptic"] = "照垒：视为使用【酒】",
  ["@@zhaolei_analeptic"] = "照垒<font color='red'><b>【酒】</font>",
  ["@@zhaolei_slash"] = "照垒<font color='red'><b>【杀】</font>",
}

zhaolei:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "zhaolei_slash", 3)
  player.room:setPlayerMark(player, "zhaolei_analeptic", 2)
end)

zhaolei:addEffect("viewas", {
  card_filter = Util.FalseFunc,
  pattern = "analeptic",
  prompt = "#3s__zhaolei-analeptic",
  view_as = function(self, cards)
    local card = Fk:cloneCard("lvshi__analeptic", Card.NoSuit, 0)
    card.skillName = zhaolei.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:setPlayerMark(player, "zhaolei_analeptic", player:getMark("zhaolei_analeptic") - 1)
    if player:getMark("zhaolei_analeptic") <= 0 then
      player.room:setPlayerMark(player, "zhaolei_slash", 3)
      player.room:setPlayerMark(player, "@@zhaolei_slash", 0)
      player.room:setPlayerMark(player, "@@zhaolei_analeptic", 1)
      player:turnOver()
      use.extra_data = use.extra_data or {}
      use.extra_data.fire = true
    end
  end,
  after_use = function(self, player, use)
    local room = player.room
    if use.extra_data and use.extra_data.analepticRecover then
      player.drank = player.drank + 1 + ((use.extra_data or {}).additionalDrank or 0)
      room:broadcastProperty(player, "drank")
    else
      if player:isWounded() and not player.dead then
        room:recover({
          who = player,
          num = 1,
          recoverBy = use.from,
          card = use.card,
        })
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:getMark("zhaolei_analeptic") > 0
  end,
  enabled_at_response = function(self, player, response)
    return player:getMark("zhaolei_analeptic") > 0
  end,
})

zhaolei:addEffect(fk.AfterCardUseDeclared, {
  is_delay_effect = true,
  priority = 0.11,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhaolei.name, true) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "zhaolei_slash", player:getMark("zhaolei_slash") - 1)
    if player:getMark("zhaolei_slash") <= 0 then
      player.room:setPlayerMark(player, "zhaolei_analeptic", 2)
      player.room:setPlayerMark(player, "@@zhaolei_analeptic", 0)
      player.room:setPlayerMark(player, "@@zhaolei_slash", 1)
      player:turnOver()
      data.extra_data = data.extra_data or {}
      data.extra_data.fire = true
    end
  end,
})

zhaolei:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhaolei.name, true) and (data.card.trueName == "slash"
    or data.card.trueName == "analeptic") and data.extra_data and data.extra_data.fire
  end,
  on_use = function(self, event, target, player, data)
    player.room:askToUseVirtualCard(player, {
        name = "lvshi__fire_attack",
        cancelable = false,
    })
  end,
})

zhaolei:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    if player:hasSkill(zhaolei.name) and player:getMark("zhaolei_slash") <= 0 then
      return card.trueName == "slash"
    end
  end,
})

return zhaolei